<?php
class HtmlTag extends Tag
{
    /**
     * 标签声明
     * @var array
     */
    public $Tag = array(
    	//文章标签
        'arclist' 	=> array('block' => 1, 'level' => 4),
    	'pagelist'	=> array('block' => 1, 'level' => 4),
    	'pageshow'	=> array('block' => 0, 'level' => 0)
    );
    /**
     * 文章标签
     * @param $attr 属性
     * @param $content 内容
     * @param $hd HdView模型引擎对象
     */
    public function _arclist($attr, $content, &$hd)
    {
        $cid = isset($attr['cid']) ? $attr['cid'] : '';
        $titlelen = isset($attr['titlelen']) ? $attr['titlelen'] : 20;
        $limit = isset($attr['limit']) ? $attr['limit'] : 10;
        $php =<<<php
<?php
		\$where = array('cid'=>$cid);
        \$data = K('Article')->where(\$where)->limit($limit)->all();
        foreach (\$data as \$k => \$field) {
        	\$field['num'] = \$k+1;
        	\$field['url'] = U('Index/article',array('aid'=>\$field['aid']));
?>
php;
		$php .= $content;
		$php .= "<?php } ?>";
        return $php; 

    }
    //一般用于栏目页文章分页显示

    public function _pagelist($attr, $content, &$hd){
    	$limit = isset($attr['limit']) ? $attr['limit'] : 10;
    	$titlelen = isset($attr['titlelen']) ? $attr['titlelen'] : 30;

    	$php =<<<php
<?php
    		\$cid = \$_GET['cid'];
    		\$where = array('cid'=>\$cid); 
    		\$total = K('Article')->where(\$where)->count();
    		\$page = new Page(\$total,$limit);
    		\$data = K('Article')->where(\$where)->limit(\$page->limit())->all();
    		foreach (\$data as \$key => \$field) {
    			\$field['url'] = U('Index/article',array('aid'=>\$field['aid']));
?>
php;
		$php .= $content;
		$php .= "<?php } ?>";
		return $php;
    }

    public function _pageshow(){
    	return "<?php echo \$page->show(2); ?>";
    }
}

?>